package com.pr.makfilm.service.impl;

import com.pr.makfilm.dao.IAbstractDao;
import com.pr.makfilm.dao.IRoomPlaceDao;
import com.pr.makfilm.domain.ObjectStateEnum;
import com.pr.makfilm.domain.Room;
import com.pr.makfilm.domain.RoomPlace;
import com.pr.makfilm.domain.RoomPlaceTypeEnum;
import com.pr.makfilm.service.IRoomPlaceService;
import com.pr.makfilm.service.IRoomService;
import com.pr.makfilm.service.util.SidUtils;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.List;

/**
 * Created with IntelliJ IDEA.
 * User: Pawel
 * Date: 17.09.13
 * Time: 23:04
 * To change this template use File | Settings | File Templates.
 */
@Service(RoomPlaceServiceImpl.BEAN_NAME)
public class RoomPlaceServiceImpl extends AbstractServiceImpl<RoomPlace> implements IRoomPlaceService
{
   public static final String BEAN_NAME = "roomPlaceService";

   @Resource
   private IRoomPlaceDao roomPlaceDao;

   @Resource
   private IRoomService roomService;

   @Override
   protected IAbstractDao<RoomPlace> getDao()
   {
      return roomPlaceDao;
   }

   @Override
   @Transactional(readOnly = true)
   public List<RoomPlace> getByRoom(Room room)
   {
      return roomPlaceDao.getByRoom(room);
   }

   @Override
   @Transactional(readOnly = false)
   public RoomPlace create(Room room, int column, int row, RoomPlaceTypeEnum type)
   {
      RoomPlace place = new RoomPlace();
      Room oldRoom = roomService.getBySid(room.getSid());
      place.setColumn(column);
      place.setRow(row);
      place.setRoom(oldRoom);
      place.setType(type);
      place.setObjectState(ObjectStateEnum.ACTIVE);
      place.setSid(SidUtils.generate());
      return save(place);
   }
}
